package com.turing.manage.guke;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;

import com.turing.dao.Dao;
import com.turing.dao.DaoImpl;

public class GuKeService {
	
	Dao dao = new DaoImpl();
	
	public List<Map<String, Object>> queryClasssAll() throws ClassNotFoundException, SQLException {
		return dao.executeQueryForList("select * from guke");
	}

	public void addClasss(String guke_name, String guke_sex, String guke_age, String guke_money, String guke_time) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
			String sql="insert into guke values('"+(int)(Math.random()*100)+"',?,?,?,?,?)";
			
			int [] types=new int [5];
			types[0]=Types.VARCHAR;
			types[1]=Types.VARCHAR;
			types[2]=Types.VARCHAR;
			types[3]=Types.VARCHAR;
			types[4]=Types.VARCHAR;
			
			Object [] values=new Object[5];
			values[0]=guke_name;
			values [1] =guke_sex;
			values [2] =guke_age;
			values [3] =guke_money;
			values [4] =guke_time;

			dao.executeUpdate(sql, types, values);
		
	}

	/**
	 *  
	 * @param classs_id
	 * @return
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public Map<String, Object> queryClassById(String guke_id) throws ClassNotFoundException, SQLException {
		
		
		return dao.executeQueryForMap("select * from guke where guke_id='"+guke_id+"'");
		
	}

	/**
	 *  desc 
	 
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	public void updateClasss(String guke_id, String guke_name,String guke_sex,  String guke_age, String guke_money, String guke_time) throws ClassNotFoundException, SQLException {
			dao.executeUpdate("update guke set guke_name='"+guke_name+"'"
								
					+ ",guke_sex='"+guke_sex+"',"
								+ "guke_age='"+guke_age+"',"
								
								+ "guke_money='"+guke_money+"',"
								+ "guke_time='"+guke_time+"' "
								+ "where guke_id='"+guke_id+"'");
	}

	/**
	 *  desc 实现级联删除+批量删除
	 * @param delids
	 * @throws IOException 
	 * @throws SQLException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */
	public void deleteClasssByIds(String[] delids) throws ClassNotFoundException, FileNotFoundException, SQLException, IOException {
		for(int i =0;i<delids.length;i++)
	     {
		     
	        //1.根据班级的id找到在这个教室考试的考生的准考证号，删除这些准考证号对应的成绩
		    String sql1=" delete from guke where guke_id='"+delids[i]+"'  ";
		
		    dao.executeUpdate(sql1);
		  
		     }
		
		
	}

}
